#!/bin/bash

pushd "$(dirname $0)" >/dev/null && source common.sh && popd >/dev/null

cd $APP_DIR

# Check if anything has changed since the last update.
if [ -f messages.timestamp ]; then
    changed=$(find . ../tools/setup.py \
        \( -name '*.py' -or -name '*.html' -or -name '*.po' \) \
        -newer messages.timestamp)
else
    changed=yes
fi

# Run a Django administration command using the version of Django that was
# installed for the currently selected version of Python.
function django_admin() {
  $PYTHON -c 'from django.core import management; management.execute_from_command_line()' "$@"
}

# If something has changed since the last update, do the update.
if [ -n "$changed" ]; then
    django_admin makemessages -a -e '.py,.html,.txt' && \
        django_admin compilemessages && \
        touch messages.timestamp
else
    echo 'Message files are up to date.'
fi

$TOOLS_DIR/find_missing_translations
